﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using System.Xml;
using System.Xml.Serialization;

using Twilio.TwilML.BaseTypes;

namespace Twilio.TwilML
{
    public class Dial : ResponseVerb
    {
        [XmlAttribute("action"), DefaultValue(null)]
        public string Action { get; set; }

        [XmlAttribute("method"), DefaultValue(HttpMethod.Post)]
        public HttpMethod Method { get; set; }

        private int _Timeout = 30;
        [XmlAttribute("timeout"), DefaultValue(30)]
        public int Timeout
        {
            get
            {
                return _Timeout;
            }
            set
            {
                if (value < 0) throw new ArgumentOutOfRangeException("Timeout", "Timeout must be a positive integer.");
                else _Timeout = value;
            }
        }

        [XmlAttribute("hangupOnStar"), DefaultValue(false)]
        public bool HangupOnStar { get; set; }

        private int _TimeLimit = 14400;
        [XmlAttribute("timeLimit"), DefaultValue(14400)]
        public int TimeLimit
        {
            get
            {
                return _TimeLimit;
            }
            set
            {
                if (value < 0) throw new ArgumentOutOfRangeException("TimeLimit", "TimeLimit must be a positive integer.");
                else _TimeLimit = value;
            }
        }

        [XmlAttribute("callerId"), DefaultValue(null)]
        public string CallerId { get; set; }

        [XmlElement("Number", typeof(Number)), XmlElement("Conference", typeof(Conference))]
        public List<DialNoun> Items { get; set; }

        public Dial() 
        {
            Items = new List<DialNoun>();
        }
        public Dial(string action) : this()
        {
            Action = action;
        }

        [XmlIgnore]
        public BaseTypes.DialNoun this[int index]
        {
            get { return Items[index]; }
        }

        public Number Append(Number number)
        {
            Items.Add(number);
            return number;
        }
        public Conference Append(Conference conference)
        {
            Items.Add(conference);
            return conference;
        }
    }
}
